<?php
/**
 * 住院病人模型
 * Created by PhpStorm.
 * User: zhang-hong
 * Date: 2017/3/7
 * Time: 13:34
 */
class PatientBasicInfoModel extends BaseModel {

    //返回给终端的可执行sql语句的字段名称数组
    public $_field_arr = [
        'zhuyuan_id', 'patient_id', 'xingming', 'xingbie', 'nianling', 'zhuyuan_bingqu',
        'ruyuan_riqi_time', 'bingchuang_hao', 'hulijibie', 'zhenduan', 'zhuangtai',
        'his_display_zhuyuanhao', 'zhuzhenyishi', 'zerenhushi', 'ruyuan_qingkuang',
        'yiliaofukuanfangshi', 'shengri', 'bingchuang_fenzu', 'chushengdi', 'gongzuo_dianhua',
        'juzhu_dianhua','lianxiren_dianhua','blood_type','guominshi','zhusu', 'shenfenzheng_hao',
        'chuyuan_riqi_time','modify_time','huanzhe_leixing','bingchuang_order','release_seat'
    ];

    //获取发热病人
    public function getfarelist($yiyuan_id,$user_department)
    {
        $this->yiyuan_id = $yiyuan_id;
        $zhuyuan_basic_info = DB::select("a.patient_id","a.zhuyuan_id","b.xingming","b.nianling","b.xingbie",
"a.zhuyuan_bingqu","a.bingchuang_hao","a.ruyuan_riqi_time","a.hulijibie","a.zhenduan")
            ->from(array("zhuyuan_basic_info","a"))
            ->join(array("patient_basic_info","b"))
            ->on("a.patient_id","=","b.patient_id")
            ->where("a.yiyuan_id","=",$this->yiyuan_id)
            ->and_where("a.zhuyuan_bingqu","=",$user_department)
            ->and_where("a.zhuangtai","=","住院中")
            ->execute()
            ->as_array();
        return $zhuyuan_basic_info;
    }

    //获取所有病人状态
    public function getAllpatientStatus(array $zhuayun_bingren,$yiyuan_id)
    {
        $this->yiyuan_id = $yiyuan_id;
        $fare_info = DB::select()
            ->from("zhuyuan_fare_level")
            ->where("yiyuan_id","=",$this->yiyuan_id)
            ->and_where("fare_level",">",0)
            ->and_where("zhuyuan_id","in",$zhuayun_bingren)
            ->execute()
            ->as_array();
        return $fare_info;
    }
    //最后一次体温测量结果
    public function getLastShuju($yiyuan_id,$zhuyuan_id,$zhuyuan_tizheng)
    {
        $this->yiyuan_id = $yiyuan_id;
        $last_shuju = DB::select()
            ->from($zhuyuan_tizheng)
            ->where("zhuyuan_id","=",$zhuyuan_id)
            ->and_where("yiyuan_id","=",$this->yiyuan_id)
            ->and_where("jiancha_type","=","体温")
            ->and_where("jiancha_fangshi","=","腋温")
            ->order_by("jiancha_time","DESC")
            ->execute()
            ->offsetGet(0);
        return $last_shuju;
    }

}